package woa.sort.test20241118;

import java.util.Arrays;

/**
 * @author wangpeng
 * @version 1.0
 * @date 2024/11/18 20:22
 */
public class InsertSort {

    public static void main(String[] args) {
        int[] arr = new int[]{4,3,1,2,71};
        sort(arr);
        System.out.println(Arrays.toString(arr));
    }

    public static void sort(int[] arr) {
        int n = arr.length;
        if (n <= 1) {
            return;
        }

        for (int i = 1; i < n; i++) {
            int temp = arr[i];
            int j = i - 1;
            for (; j >= 0 && arr[j] > temp; j--) {
                arr[j + 1] = arr[j];
            }
            arr[j + 1] = temp;
        }
    }
}
